package com.chiffoyqc.utils;

import java.io.UnsupportedEncodingException;
import java.util.Base64;

/**
 * Created by Administrator on 2018/7/12.
 */
public class Base64Util {

    /**
     * 编码
     * */
    public static String encode(String str){
        Base64.Encoder encoder = Base64.getEncoder();
        try {
            String result = encoder.encodeToString(str.getBytes("utf-8"));
            return result;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 解码
     * */
    public static String decode(String str){
        Base64.Decoder decoder = Base64.getDecoder();
        try {
            String result = new String(decoder.decode(str), "UTF-8");
            return result;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }

}
